<#assign security=JspTaglibs["/WEB-INF/security.tld"] />
<#include "../../select.ftl" />
<!DOCTYPE html>
<html>
<head>
<title>会员管理</title>
<script type="text/javascript">

$(function () {
    $("input[name=billTime]").focus(function () {
        WdatePicker({dateFmt: 'yyyy-MM-dd'});
    })
    $("input[name=endDate]").focus(function () {
        WdatePicker({dateFmt: 'yyyy-MM-dd'});
    })
    $("input[name=endendDate]").focus(function () {
        WdatePicker({dateFmt: 'yyyy-MM-dd'});
    })

    $("div[class='tooltip fade top in']").hide();
});


function popAddOrModify(id) {
    var data = {};
    var url = '${absoluteContextPath}/members/ykManage';
    if (id != undefined) {
        data.id = id;
        url = url + "/goEdit";
    } else {
        url = url + "/goAdd";
    }
    $.ajax({
        url: url,
        type: 'post',
        data: data,
        success: function (data) {
            var data = JSON.parse(data);
            if (data.returnCode == 1) {
                var pop_div = $('#myModal');
                pop_div.html(data.content.data);
                pop_div.modal('show');
            } else {
                $.showMessage({parentId: "showMessage", message: "数据加载异常！", type: "success"});
            }
        }
    });
}

function popBathAddOrModify() {
    var i = 0;
    $("input[name=ids]").each(function () {
        if ($(this).prop("checked")) {
            i++;
        }
    });
    if (i == 0) {
        $.showMessage({parentId: "showMessage", message: "请选择您要删除的记录！", type: "success"});
        return false;
    } else {
        var values = "";
        $("input[name=ids]").each(function () {
            if ($(this).prop("checked")) {
                values += $(this).val() + ",";
            }
        });
        $.post("${absoluteContextPath}/members/ykManage/deletes", {
            'ids': values
        }, function (data) {
            data = JSON.parse(data);
            if (data.returnCode == 1) {
                var pop_div = $('#myModal');
                pop_div.html(data.content.data);
                pop_div.modal('show');
            } else {
                $.showMessage({parentId: "showMessage", message: "数据删除异常！", type: "error"});
            }
        });
    }
}


function deleteYkManage() {
    var i = 0;
    $("input[name=ids]").each(function () {
        if ($(this).prop("checked")) {
            i++;
        }
    });
    if (i == 0) {
        $.showMessage({parentId: "showMessage", message: "请选择您要删除的记录！", type: "success"});
        return false;
    } else {
        $.confirm({
            confirm: function () {
                var values = "";
                $("input[name=ids]").each(function () {
                    if ($(this).prop("checked")) {
                        values += $(this).val() + ",";
                    }
                });
                $("#confirmModal").modal("hide");
                $.post("${absoluteContextPath}/members/ykManage/delete", {
                    'ids': values
                }, function (data) {
                    data = JSON.parse(data);
                    if (data.returnCode == 1) {
                        $.showMessage({parentId: "showMessage", message: "数据删除成功！", type: "success"});
                        refreshTable();
                    } else {
                        $.showMessage({parentId: "showMessage", message: "数据删除异常！", type: "error"});
                    }
                });
            }
        });
    }
}
function dorefreshProduct(target) {
    var data = {};
    var url = '${absoluteContextPath}/productSale/product';
    url = url + "/goSelectDetailed";
    $.ajax({
        url: url,
        type: 'post',
        data: data,
        success: function (data) {
            var data = JSON.parse(data);
            if (data.returnCode == 1) {
                var pop_div = $('#myModal');
                pop_div.html(data.content.data);
                pop_div.modal('show');
                $(pop_div).find("#confirm").click(function () {
                    var id = $("#selectProductId").val();
                    var name = $("#selectPproductName").val();
                    $(target).parent().find("input[name=cardId]").val(id);
                    $(target).parent().find("input[name=productName]").val(name);
                    $('#myModal').modal("hide");
                });
            } else {
                $.showMessage({parentId: "errorMessage", message: "数据加载异常！", type: "success"});
            }
        }
    });
}
function refreshTable() {
    $("input[name=currentPage]").val(1);
    $("#search_ykManage_table").ajaxSubmit({
        url: '${absoluteContextPath}/members/ykManage/ajaxList',
        success: function (data) {
            var data = JSON.parse(data);
            if (data.returnCode == 1) {
                $("#tableContent").html(data.content.data);
            } else {
                $.showMessage({parentId: "showMessage", message: "表格数据加载异常！", type: "success"});
            }
        }
    });
}
//选择客户
function dorefreshCustome(target) {
    var data = {};
    var url = '${absoluteContextPath}/members/customer';
    url = url + "/dorefreshCustome";
    $.ajax({
        url: url,
        type: 'post',
        data: data,
        success: function (data) {
            var data = JSON.parse(data);
            if (data.returnCode == 1) {
                var pop_div = $('#myModal2');
                pop_div.html(data.content.data);
                pop_div.modal('show');
                $(pop_div).find("#confirm").click(function () {
                    var id = $("#selectCardId").val();
                    var name = $("#selectCustomerName").val();
                    $(target).parent().find("input[name=cardId]").val(id);
                    $(target).parent().find("input[name=customerName]").val(name);
                    $('#myModal2').modal("hide");
                });
            } else {
                $.showMessage({parentId: "errorMessage", message: "数据加载异常！", type: "success"});
            }
        }
    });
}
//选择卡名称
function dorefreshcardtype(target) {
    var data = {};
    var url = '${absoluteContextPath}/members/cardType';
    url = url + "/dorefreshcardtype";
    $.ajax({
        url: url,
        type: 'post',
        data: data,
        success: function (data) {
            var data = JSON.parse(data);
            if (data.returnCode == 1) {
                var pop_div = $('#myModal2');
                pop_div.html(data.content.data);
                pop_div.modal('show');
                $(pop_div).find("#confirm").click(function () {
                    var id = $("#selectVipId").val();
                    var name = $("#selectProductName").val();
                    $(target).parent().find("input[name=vipId]").val(id);
                    $(target).parent().find("input[name=productName]").val(name);
                    $('#myModal2').modal("hide");
                });
            } else {
                $.showMessage({parentId: "errorMessage", message: "数据加载异常！", type: "success"});
            }
        }
    });
}
//选择分管人
function doSelctReferralsUser(target) {
    var usingOrgId = $("#orgId").val();
    var data = {};
    var url = '${absoluteContextPath}/system/user';
    url = url + "/goSelectSaleUser";
    data.usingOrgId = usingOrgId;
    $.ajax({
        url: url,
        type: 'post',
        data: data,
        success: function (data) {
            var data = JSON.parse(data);
            if (data.returnCode == 1) {
                var pop_div = $('#myModal2');
                pop_div.html(data.content.data);
                pop_div.modal('show');
                $(pop_div).find("#confirm").click(function () {
                    var id = $("#selectUserId").val();
                    var name = $("#selectUserName").val();
                    $(target).parent().find("input[name=healthFg]").val(id);
                    $(target).parent().find("input[name=userNameFg]").val(name);
                    $('#myModal2').modal("hide");
                });
            } else {
                $.showMessage({parentId: "showMessage", message: "数据加载异常！", type: "success"});
            }
        }
    });
}


//选择促会人
function doSelctIllIndex(target) {
    var illIndexId = $(target).parent().find("input[name=healthCh]").val();
    var illIndexName = $(target).parent().find("input[name=userName]").val();
    var data = {};
    var url = '${absoluteContextPath}/system/user';
    url = url + "/goSelectIllIndex";
    data.selectType = "Multiselect";
    $.ajax({
        url: url,
        type: 'post',
        data: data,
        success: function (data) {
            var data = JSON.parse(data);
            if (data.returnCode == 1) {
                var pop_div = $('#selectIllIndexModal');
                pop_div.html(data.content.data);
                pop_div.modal('show');
                $(pop_div).find("#confirm").click(function () {
                    var illIndexIds = "";
                    var illIndexNames = "";
                    $("#search_illIndexs_table input[name=ids]").each(function () {
                        if ($(this).prop("checked")) {
                            illIndexIds += $(this).parent().parent().children("td:eq(1)").text() + ",";
                            illIndexNames += $(this).parent().parent().children("td:eq(2)").text() + ",";
                        }
                    });
                    //省略最后一个逗号
//                    if (illIndexIds.contains(",")) {
//                        illIndexIds = illIndexIds.substring(0, illIndexIds.lastIndexOf(","));
//                        illIndexNames = illIndexNames.substring(0, illIndexNames.lastIndexOf(","));
//                    }
                    $(target).parent().find("input[name=healthCh]").val(illIndexIds);
                    $(target).parent().find("input[name=userName]").val(illIndexNames);
                    $('#selectIllIndexModal').modal("hide");
                });
            } else {
                $.showMessage({parentId: "errorMessage", message: "数据加载异常！", type: "success"});
            }
        }
    });
}


//选择引荐人
function doSelctHealthYj(target) {
    var illIndexId = $(target).parent().find("input[name=healthYj]").val();
    var illIndexName = $(target).parent().find("input[name=userNameYj]").val();
    var data = {};
    var url = '${absoluteContextPath}/system/user';
    url = url + "/goSelectIllIndex";
    data.selectType = "Multiselect";
    $.ajax({
        url: url,
        type: 'post',
        data: data,
        success: function (data) {
            var data = JSON.parse(data);
            if (data.returnCode == 1) {
                var pop_div = $('#selectIllIndexModal');
                pop_div.html(data.content.data);
                pop_div.modal('show');
                $(pop_div).find("#confirm").click(function () {
                    var illIndexIds = "";
                    var illIndexNames = "";
                    $("#search_illIndexs_table input[name=ids]").each(function () {
                        if ($(this).prop("checked")) {
                            illIndexIds += $(this).parent().parent().children("td:eq(1)").text() + ",";
                            illIndexNames += $(this).parent().parent().children("td:eq(2)").text() + ",";
                        }
                    });
                    //省略最后一个逗号
//                    if (illIndexIds.contains(",")) {
//                        illIndexIds = illIndexIds.substring(0, illIndexIds.lastIndexOf(","));
//                        illIndexNames = illIndexNames.substring(0, illIndexNames.lastIndexOf(","));
//                    }
                    $(target).parent().find("input[name=healthYj]").val(illIndexIds);
                    $(target).parent().find("input[name=userNameYj]").val(illIndexNames);
                    $('#selectIllIndexModal').modal("hide");
                });
            } else {
                $.showMessage({parentId: "errorMessage", message: "数据加载异常！", type: "success"});
            }
        }
    });
}


</script>
</head>
<body>

<div class="breadcrumbs">
    <ol class="breadcrumb">
        <li><a href="${absoluteContextPath}/home"><i class="fa fa-home"></i>首页</a></li>
        <li><a href="#">会员管理</a></li>
        <li class="active">会员管理</li>
    </ol>
</div>

<div class="main">
    <!-- row -->
    <div class="row">
        <div class="col-md-12">
            <section class="tile">
                <!-- tile body -->
                <div class="tile-body">
                    <div id="showMessage"><#include "../../message.ftl" /></div>
                    <div class="form-horizontal">
                        <form id="search_ykManage_table" action="${absoluteContextPath}/members/ykManage/list"
                              method="post">
                            <input type="hidden" name="pageSize" value="${ykManagesTable.page.pageSize}"/>
                            <input type="hidden" name="currentPage" value="${ykManagesTable.page.currentPage}"/>


                            <div class="row">
                                <div class="form-group col-md-4">
                                    <label class="col-sm-4 control-label" for="exampleInputEmail2">下单日期</label>

                                    <div class="col-sm-8">

                                        <input class="form-control" name="billTime"
                                               value="${ykManageParams.billTime!''}" placeholder="" type="text">
                                    </div>
                                </div>
                                <div class="form-group col-md-4">
                                    <label class="col-sm-4 control-label" for="exampleInputEmail2">卡号</label>

                                    <div class="col-sm-8">
                                        <input name="cardId" value="${ykManageParams.cardId!''}"
                                               type="text" class="form-control">
                                    </div>
                                </div>
                                <div class="form-group col-md-4">
                                    <label class="col-sm-4 control-label" for="exampleInputEmail2">客户姓名</label>

                                    <div class="col-sm-8">
                                        <input name="customerName" value="${ykManageParams.customerName!''}"
                                               type="text" class="form-control"/>

                                    </div>
                                </div>

                            </div>
                            <div class="row">
                                <div class="form-group col-md-4">
                                    <label class="col-sm-4 control-label" for="exampleInputEmail2">会员类型</label>

                                    <div class="col-sm-8">

                                    <@select name="vipType" value="${ykManageParams.vipType!''}" list=vipTypeList class="form-control"/>
                                    </div>
                                </div>


                                <div class="form-group col-md-4">
                                    <label class="col-sm-4 control-label" for="exampleInputEmail2">渠道类型</label>

                                    <div class="col-sm-8">

                                    <@select name="channelType" value="${ykManageParams.channelType!''}" list=channelTypeList class="form-control"/>
                                    </div>
                                </div>
                                <div class="form-group col-md-4">
                                    <label class="col-sm-4 control-label" for="exampleInputEmail2">产品名称</label>

                                    <div class="col-sm-8">

                                        <input name="productName" value="${ykManageParams.productName!''}"
                                               type="text" class="form-control">
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="form-group col-md-4">
                                    <label class="col-sm-4 control-label" for="exampleInputEmail2">分管人</label>

                                    <div class="col-sm-8">

                                        <input class="form-control" name="userNameFg"
                                               value="${ykManageParams.userNameFg!''}" placeholder="" type="text">

                                    </div>
                                </div>

                                <div class="form-group col-md-4">
                                    <label class="col-sm-4 control-label" for="exampleInputEmail2">到期日期</label>

                                    <div class="col-sm-8">

                                        <input class="form-control" name="endDate"
                                               value="${ykManageParams.endDate!''}" placeholder="" type="text">
                                    </div>
                                </div>
                                <div class="form-group col-md-4">
                                    <label class="col-sm-4 control-label" for="exampleInputEmail2">~</label>

                                    <div class="col-sm-8">
                                        <input class="form-control" name="endendDate"
                                               value="${ykManageParams.endendDate!''}" placeholder="" type="text">
                                    </div>
                                </div>
                                <div class="form-group col-md-4">
                                    <label class="col-sm-4"></label>

                                    <div class="col-sm-8">
                                        <button type="button" class="btn btn-primary" onclick="refreshTable()">查询
                                        </button>
                                        <button type="reset" class="btn btn-default">重置</button>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </section>
            <section class="tile">
                <div class="tile-header">
                    <h1>
                        <button type="button" class="btn btn-green" onclick="popAddOrModify();"><i
                                class="fa fa-plus"></i><span class="margin-left-5">新增</span></button>

                        <button type="button" class="btn btn-cyan" onclick="deleteYkManage();"><i
                                class="fa fa-trash-o"></i><span class="margin-left-5">删除</span></button>

                        <button type="button" class="btn btn-red" onclick="popBathAddOrModify();"><i
                                class="fa fa-plus"></i><span class="margin-left-5">批量分配</span></button>
                    </h1>
                </div>
                <div class="tile-body nopadding">
                    <div class="table-responsive" id="tableContent">
                    <#include "table.ftl"/>
                    </div>
                </div>
            </section>
        </div>
    </div>
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    </div>
    <div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    </div>
    <div class="modal fade" id="selectIllIndexModal" tabindex="-1" role="dialog"
         aria-labelledby="selectIllIndexModalLabel" aria-hidden="true"></div>
</div>
</body>
</html>
